﻿<template>
    <div style="height:100%;">
        <Row>
            <Col span="24" class="col-margin">
            <!--根据需求删除不不要查询条件-->
            填报年份：
            <Select v-model="searchModel.FillInYear" placeholder="全部" :label-in-value="true"  style="width:200px">
                <Option v-for="item in yearList" :value="item.DictValue" :key="item.DictValue">{{ item.DictText }}</Option>
            </Select>
            填报周期：
            <Select  v-model="searchModel.TimesCycle" placeholder="请选择季节值..." style="width:100px;">
                <!-- <Option value="0" >全部</Option> -->
                <Option :value="item.DictValue" v-for="item in QuarterList" :key="item.DictValue">{{item.DictText}}</Option>
            </Select>
            <Button icon="ios-search" type="ghost" @click="getPageData()">查询</Button>
            </Col>
        </Row>
        <div v-show="isCreated">
        <Row>
            <Col span="24" class="col-margin">
                <Table size="small"  :height="clientHeight" border  :columns="columnsList" :data="datas.rows" no-data-text='暂无数据...'></Table>
            </Col>
        </Row>
        <Row>
            <Col span="24">
            <Page class="page-style" :total="datas.total" placement="top" @on-change="getPageNumber" :page-size="searchModel.PageSize" :page-size-opts='pageSizeOpts' show-sizer @on-page-size-change="getPageSize" show-total show-elevator></Page>
            </Col>
        </Row> 
        </div>
        <div v-show="!isCreated" class="NoCreatedDiv">
            <h1>{{ReportLine}}</h1>
        </div>
        <Modal v-model="showType" :mask-closable="false" width="1500"  :styles="{top: '20px'}">
            <p slot="header" class="title">
                <Icon type="ios-paper" size="20"></Icon>
                <span style="font-size: 20px">（二）{{TimesCycleName}}-马铃薯生产情况统计表</span>
            </p>
            <p slot="close">
                <Icon type="close-circled" color="red" size=25></Icon>
            </p>
            <!-- <Row>
                <Col span="24" class="col-margin">
                    <Button icon="plus" type="primary" :disabled="!pShow" @click="addItem()">新增</Button>            
                </Col>
            </Row> -->
            <div style="height:600px;overflow-y:auto">
            <Form ref="dataModel" :model="{dataList}">
                <table class="reptable">                   
                    <thead>
                        <tr>                            
                            <th style="width:50px;" rowspan="3">季别</th>
                            <th rowspan="3">播种、收获时间</th>
                            <!-- <th rowspan="3">主推品种</th> -->
                            <th rowspan="3">总面积（万亩）</th>
                            <th rowspan="3">总产量（万吨）</th>
                            <th rowspan="3">平均亩产（公斤/亩）</th>
                            <th rowspan="3">亩产值（元）</th>
                            <th rowspan="3">总产值（万元）</th>
                            <th rowspan="3">技术模式</th>
                            <th rowspan="3">脱毒种薯覆盖面积（万亩）</th>
                            <th rowspan="3">脱毒种薯覆盖率（%）</th>
                            <th rowspan="3">地膜覆盖面积（万亩）</th>
                            <th rowspan="3">膜下滴灌面积（万亩）</th>
                            <th rowspan="3">配方施肥面积（万亩）</th>
                            <th rowspan="3">免耕栽培面积（万亩）</th>                                                      
                        </tr>                        
                    </thead>
                    <tbody>
                        <tr v-for="(dataModel,index) in dataList" :key="index">
                            <td style="width:50px;">                            
                                <Form-item  prop="SeasonDict">
                                    {{dataModel.SeasonDict}}
                                </Form-item>   
                            </td>
                            <td>
                                <Form-item  prop="PHTime">
                                    <!-- <Input v-model="dataModel.PHTime" icon="ios-calendar-outline" v-show="!PHTimeopen" @on-click="PHTimeopen=true" style="width: 250px"></Input> -->
                                    <DatePicker :value="PHTimes[index]" format="yyyy年MM月dd日" 
                                             type="daterange" placement="bottom-start" 
                                             @on-change = "dataModel.PHTime=($event).join('-')"
                                             placeholder="请选择" style="width: 250px">
                                    </DatePicker>
                                </Form-item>   
                            </td>
                            <!-- <td>
                                <Form-item  prop="MainVariety">
                                    <Select v-model="MainVarietys[index]" multiple placeholder="请选择"   style="width:220px">
                                        <Option v-for="item in VarietyList" :value="item.DictText" :key="item.DictValue">{{ item.DictText }}</Option>
                                    </Select>
                                </Form-item>   
                            </td> -->
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.TotalArea'" :rules="commonRule">
                                    <Input v-model="dataModel.TotalArea" ></Input>
                                </Form-item> 
                            </td>  
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.TotalYield'" :rules="commonRule">
                                    <Input v-model="dataModel.TotalYield" ></Input>
                                </Form-item>   
                            </td>
                            <td>
                                <Form-item  prop="AvgMuYield">
                                    {{(dataModel.TotalArea&&dataModel.TotalYield&&dataModel.TotalArea != 0)?dataModel.AvgMuYield=(dataModel.TotalYield/dataModel.TotalArea*1000).toFixed(2):0}}
                                   
                                </Form-item>   
                            </td>
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.MuOutput'" >
                                    <!-- <Input v-model="dataModel.MuOutput" ></Input> -->
                                    {{(dataModel.TotalArea&&dataModel.TotalOutput&&dataModel.TotalArea != 0)?dataModel.MuOutput=(dataModel.TotalOutput/dataModel.TotalArea).toFixed(1):0}}
                                   
                                </Form-item>  
                            </td> 
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.TotalOutput'" :rules="commonRule">
                                    <Input v-model="dataModel.TotalOutput" ></Input>
                                </Form-item>   
                            </td>
                            <td style="text-align:left;">
                                <Poptip trigger="hover" title="请选择" width="400" placement="bottom" @on-popper-hide="saveTechModel(index)"> 
                                    <div slot="content" style="height:300px;"> 
                                        1.
                                        <div class="col-margin">                                                                            
                                            <Checkbox-group v-model="aTechmodel" >
                                                <Checkbox :label="aItem" v-for="(aItem,index1) in aTechmodels" :key="index1"></Checkbox>
                                            </Checkbox-group>
                                        </div>
                                        2.
                                        <div class="col-margin">
                                            <Checkbox-group v-model="bTechmodel" >
                                                <Checkbox :label="bItem" v-for="(bItem,index) in bTechmodels" :key="index">{{bItem}}</Checkbox>
                                            </Checkbox-group>
                                        </div>
                                        3.
                                        <div class="col-margin"> 
                                            <Checkbox-group v-model="cTechmodel" >
                                                <Checkbox :label="cItem" v-for="(cItem,index) in cTechmodels" :key="index">{{cItem}}</Checkbox>
                                            </Checkbox-group>
                                        </div>
                                        4.
                                        <div class="col-margin">
                                            <Checkbox-group v-model="dTechmodel" >
                                                <Checkbox :label="dItem" v-for="(dItem,index2) in dTechmodels" :key="index2">{{dItem}}</Checkbox>
                                            </Checkbox-group>
                                        </div>
                                        5.
                                        <div class="col-margin">
                                            <Checkbox-group v-model="eTechmodel" >
                                                <Checkbox :label="eItem" v-for="(eItem,index3) in eTechmodels" :key="index3">{{eItem}}</Checkbox>
                                            </Checkbox-group>
                                        </div>                                       
                                    </div>
                                    <Form-item  prop="TechModel">
                                        <Input v-model="dataModel.TechModel" type="textarea" :autosize="true"></Input>
                                    </Form-item>
                                </Poptip>   
                            </td>
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.tdSeedArea'" :rules="commonRule">
                                    <Input v-model="dataModel.tdSeedArea" ></Input>
                                </Form-item>   
                            </td>
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.SeedCoverage'" >
                                    {{(dataModel.TotalArea&&dataModel.tdSeedArea&&dataModel.TotalArea != 0)?dataModel.SeedCoverage=(dataModel.tdSeedArea/dataModel.TotalArea*100).toFixed(2):0}}
                                   
                                </Form-item>   
                            </td>
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.MulchArea'" :rules="commonRule">
                                    <Input v-model="dataModel.MulchArea" ></Input>
                                </Form-item>   
                            </td>
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.DripArea'" :rules="commonRule">
                                    <Input v-model="dataModel.DripArea" ></Input>
                                </Form-item>  
                            </td> 
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.FertilizerArea'" :rules="commonRule">
                                    <Input v-model="dataModel.FertilizerArea" ></Input>
                                </Form-item>   
                            </td>
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.NoCultivationArea'" :rules="commonRule">
                                    <Input v-model="dataModel.NoCultivationArea" ></Input>
                                </Form-item>   
                            </td>                            
                        </tr>
                    </tbody>
                </table>
                <div class="hrdiv"><hr class="hr1" /></div>
                <table class="reptable" >                   
                    <thead>
                        <tr>                            
                            <th style="width:50px;" rowspan="3">季别</th>                            
                            <th colspan="6">净作</th>
                            <th colspan="6">间作、套种</th>
                            <th colspan="5">机械化生产</th>                                                        
                        </tr>
                        <tr>
                            <th rowspan="2">面积（万亩）</th>
                            <th rowspan="2">产量（万吨）</th>
                            <th rowspan="2">平均亩产（公斤/亩）</th>
                            <th rowspan="2">亩产值（元）</th>
                            <th rowspan="2">种植密度（株/亩）</th>
                            <th rowspan="2">技术模式</th>
                            <th rowspan="2">面积（万亩）</th>
                            <th rowspan="2">马铃薯产量（万吨）</th>
                            <th rowspan="2">马铃薯平均亩产（公斤/亩）</th>
                            <th rowspan="2">复合亩产（公斤/亩）</th>
                            <th rowspan="2">复合亩产值（元）</th>
                            <th rowspan="2">种植模式</th>
                            <th rowspan="2">机械播种面积（万亩）</th>
                            <th colspan="3">机械田间管理面积（万亩）</th>
                            <th rowspan="2">机械收获面积（万亩）</th>                            
                        </tr>
                        <tr>
                            <th>其中：中耕培土</th>
                            <th>施肥</th>
                            <th>施药</th>                                                  
                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="(dataModel,index) in dataList" :key="index"> 
                            <td style="width:50px;">                            
                                <Form-item  prop="SeasonDict">
                                    {{dataModel.SeasonDict}}
                                </Form-item>   
                            </td>                           
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.JZArea'" :rules="commonRule">
                                    <Input v-model="dataModel.JZArea" ></Input>
                                </Form-item>
                            </td>   
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.JZYield'" :rules="commonRule">
                                    <Input v-model="dataModel.JZYield" ></Input>
                                </Form-item>   
                            </td>
                            <td>
                                <Form-item  prop="JZAvgMuYield">
                                    {{(dataModel.JZArea&&dataModel.JZYield&&dataModel.JZArea != 0)?dataModel.JZAvgMuYield=(dataModel.JZYield/dataModel.JZArea*1000).toFixed(2):0}}
                                   
                                </Form-item>   
                            </td>
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.JZMuOutput'" :rules="commonRule">
                                    <Input v-model="dataModel.JZMuOutput" ></Input>
                                </Form-item>   
                            </td>
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.JZDensity'" :rules="commonRule">
                                    <Input v-model="dataModel.JZDensity" ></Input>
                                </Form-item>  
                            </td> 
                            <td style="text-align:left;">
                                <Poptip trigger="hover" title="请选择" width="400" placement="bottom" @on-popper-hide="saveJZTechModel(index)"> 
                                    <div slot="content" style="height:300px;"> 
                                        1.
                                        <div class="col-margin">                                                                            
                                            <Checkbox-group v-model="JZaTechmodel" >
                                                <Checkbox :label="aItem" v-for="(aItem,index1) in aTechmodels" :key="index1"></Checkbox>
                                            </Checkbox-group>
                                        </div>
                                        2.
                                        <div class="col-margin">
                                            <Checkbox-group v-model="JZbTechmodel" >
                                                <Checkbox :label="bItem" v-for="(bItem,index) in bTechmodels" :key="index">{{bItem}}</Checkbox>
                                            </Checkbox-group>
                                        </div>
                                        3.
                                        <div class="col-margin"> 
                                            <Checkbox-group v-model="JZcTechmodel" >
                                                <Checkbox :label="cItem" v-for="(cItem,index) in cTechmodels" :key="index">{{cItem}}</Checkbox>
                                            </Checkbox-group>
                                        </div>
                                        4.
                                        <div class="col-margin">
                                            <Checkbox-group v-model="JZdTechmodel" >
                                                <Checkbox :label="dItem" v-for="(dItem,index) in dTechmodels" :key="index">{{dItem}}</Checkbox>
                                            </Checkbox-group>
                                        </div>
                                        5.
                                        <div class="col-margin">
                                            <Checkbox-group v-model="JZeTechmodel" >
                                                <Checkbox :label="eItem" v-for="(eItem,index) in eTechmodels" :key="index">{{eItem}}</Checkbox>
                                            </Checkbox-group>
                                        </div>
                                    </div>
                                    <Form-item  prop="JZTechModel">
                                        <Input v-model="dataModel.JZTechModel" type="textarea" :autosize="true" ></Input>
                                    </Form-item>
                                </Poptip> 
                            </td> 
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.JTArea'" :rules="commonRule">
                                    <Input v-model="dataModel.JTArea" ></Input>
                                </Form-item> 
                            </td> 
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.JTYield'" :rules="commonRule">
                                    <Input v-model="dataModel.JTYield" ></Input>
                                </Form-item> 
                            </td>  
                            <td>
                                <Form-item  prop="JTAvgMuYield">
                                    <!-- <Input v-model="dataModel.JTAvgMuYield" ></Input> -->
                                    {{(dataModel.JTArea&&dataModel.JTYield&&dataModel.JTArea != 0)?dataModel.JTAvgMuYield=(dataModel.JTYield/dataModel.JTArea*1000).toFixed(2):0}}
                                   
                                </Form-item> 
                            </td>  
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.JTMixMuYield'" :rules="commonRule">
                                    <Input v-model="dataModel.JTMixMuYield" ></Input>
                                </Form-item>   
                            </td>
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.JTMixMuOutput'" :rules="commonRule">
                                    <Input v-model="dataModel.JTMixMuOutput" ></Input>
                                </Form-item>   
                            </td>
                            <td style="text-align:left;">
                                <Poptip trigger="hover" title="请选择" width="320" placement="bottom" @on-popper-hide="saveJTTechModel(index)"> 
                                    <div slot="content" style="height:100px;"> 
                                       
                                        <div class="col-margin">                                                                            
                                            <Checkbox-group v-model="JTaTechmodel" vertical>
                                                <!-- <Checkbox :label="aItem" v-for="(aItem,index1) in JTaTechmodels" :key="index1"></Checkbox> -->
                                                <Checkbox label="玉米间套马铃薯" ></Checkbox>
                                                <Checkbox label="甘蔗间套马铃薯" ></Checkbox>
                                                </br>
                                                <Checkbox label="玉米套种秋马铃薯" ></Checkbox>
                                                <Checkbox label="烤烟套种秋马铃薯" ></Checkbox>
                                                </br>
                                                <Checkbox label="桑园间套马铃薯" ></Checkbox>
                                            </Checkbox-group>
                                        </div>
                                    </div>
                                    <Form-item  prop="JTTechModel">
                                        <Input v-model="dataModel.JTTechModel" type="textarea" :autosize="true"></Input>
                                    </Form-item>
                                </Poptip>
                            </td> 
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.MechPlantArea'" :rules="commonRule">
                                    <Input v-model="dataModel.MechPlantArea" ></Input>
                                </Form-item>   
                            </td>
                            <td>
                                <Form-item :prop="'dataList.' + index + '.MechCultivationArea'" :rules="commonRule">
                                    <Input v-model="dataModel.MechCultivationArea" ></Input>
                                </Form-item>   
                            </td>
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.MechFertilizerArea'" :rules="commonRule">
                                    <Input v-model="dataModel.MechFertilizerArea" ></Input>
                                </Form-item>   
                            </td>
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.MechPesticideArea'" :rules="commonRule">
                                    <Input v-model="dataModel.MechPesticideArea" ></Input>
                                </Form-item>  
                            </td> 
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.MechHarvestArea'" :rules="commonRule">
                                    <Input v-model="dataModel.MechHarvestArea" ></Input>
                                </Form-item>  
                            </td>                             
                        </tr>
                    </tbody>
                </table>
                <div class="hrdiv"><hr class="hr2" /></div>
                <table class="reptable" >                   
                    <thead>
                        <tr>                            
                            <th style="width:50px;" rowspan="3">季别</th>                                                        
                            <th colspan="11">亩均收益</th>                            
                        </tr>
                        <tr>                            
                            <th colspan="7">投入（元）</th>
                            <th colspan="3">产出</th>
                            <th rowspan="2">收益（元）</th>
                        </tr>
                        <tr>                            
                            <th>种薯</th>
                            <th>肥料</th>
                            <th>农药</th>
                            <th>地膜</th>
                            <th>全生育期用工费</th>
                            <th>其他</th>
                            <th>投入合计</th>   
                            <th>平均亩产（公斤/亩）</th>
                            <th>平均单价（元/公斤）</th>
                            <th>产出合计（元）</th>                         
                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="(dataModel,index) in dataList" :key="index"> 
                            <td style="width:50px;">                            
                                <Form-item  prop="SeasonDict">
                                    {{dataModel.SeasonDict}}
                                </Form-item>   
                            </td>                                                       
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.SeedCost'" :rules="commonRule">
                                    <Input v-model="dataModel.SeedCost" ></Input>
                                </Form-item>  
                            </td> 
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.FertilizerCost'" :rules="commonRule">
                                    <Input v-model="dataModel.FertilizerCost" ></Input>
                                </Form-item>  
                            </td> 
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.PesticideCost'" :rules="commonRule">
                                    <Input v-model="dataModel.PesticideCost" ></Input>
                                </Form-item>   
                            </td>
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.MulchCost'" :rules="commonRule">
                                    <Input v-model="dataModel.MulchCost" ></Input>
                                </Form-item>   
                            </td>
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.LaborCost'" :rules="commonRule">
                                    <Input v-model="dataModel.LaborCost" ></Input>
                                </Form-item>   
                            </td>
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.OtherCost'" :rules="commonRule">
                                    <Input v-model="dataModel.OtherCost" ></Input>
                                </Form-item>   
                            </td>
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.TotalCost'" >
                                    <!-- <Input v-model="dataModel.TotalCost" ></Input> -->
                                    {{dataModel.TotalCost= (dataModel.SeedCost*1+dataModel.FertilizerCost*1+dataModel.PesticideCost*1
                                    +dataModel.MulchCost*1+dataModel.LaborCost*1+dataModel.OtherCost*1).toFixed(1)}}
                                </Form-item>   
                            </td>
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.OAvgMuYield'" :rules="commonRule">
                                    <Input v-model="dataModel.OAvgMuYield" ></Input>
                                </Form-item>  
                            </td> 
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.OAvgPrice'" :rules="commonRule">
                                    <Input v-model="dataModel.OAvgPrice" ></Input>
                                </Form-item>   
                            </td>
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.OTotalOutput'" >
                                    <!-- <Input v-model="dataModel.OTotalOutput" ></Input> -->
                                    {{dataModel.OTotalOutput=(dataModel.OAvgMuYield*1*(dataModel.OAvgPrice*1)).toFixed(1)}}
                                </Form-item>   
                            </td>
                            <td>
                                <Form-item  :prop="'dataList.' + index + '.Income'" >
                                    <!-- <Input v-model="dataModel.Income" ></Input> -->
                                    {{dataModel.Income = (dataModel.OTotalOutput*1-dataModel.TotalCost*1).toFixed(1)}}
                                </Form-item>   
                            </td>
                        </tr>
                    </tbody>
                </table>
                </Form>
                
            <div style="text-align:right;padding-top:10px">
               <Button type="ghost" v-show="rShow" @click="DataUp()" >上报</Button>
               <Button type="primary" v-show="pShow" @click="save('dataModel')" style="margin-left: 5px">保存</Button>
               <Button type="ghost" @click="showType = false" style="margin-left: 5px">关闭</Button>
          </div>
          <div v-show="ReasonShow" style="margin-top:10px;">
              <div style="background-color:#f9c912;font-size:20px;color:#1C1C1C;padding:10px;">
                  <span>审核不通过原因</span>
                </div>
              <div >
                  <Input v-model="Opinion" type="textarea" readonly :autofocus="true" :rows="4"  ></Input>
              </div>
          </div>
          </div>
            <div slot="footer" style="padding-bottom:50px">
                <Alert style="margin-top:5px;text-align:left" banner type="error">
                    填报时间：每年7月1日（冬马铃薯）、10月30日（大春马铃薯）、12月30日（秋马铃薯）
                    <p>填报说明: 1.全省范围内从乡（镇）起，逐级全面统计，由县级填报经州（市）审核后上报。</p>
                    <p>2.投入合计=种薯+肥料+农药+地膜+用工费+其他投入实际金额；产出合计=平均亩产X平均单价；收益=产出合计-投入合计。</p>                                      
                    <span slot="desc">
                    </span>
                </Alert>
            </div>
        </Modal>      
    </div>
</template>
<script>
export default {
    data() {
        const validateData = (rule, value, callback) => {
            var temp = /^[0-9]\d*(\.\d+)?$/;
            if (value||value==0) {
                if (temp.test(value) == false) {
                    callback(new Error('必须是数字！'));
                }
                else {
                    callback();
                }
            } else {
                callback(new Error('不能为空！'));
            }
        };
        return {
            isCreated:true,//是否需要显示报表
            ReportLine:'',//不显示报表时所显示文字
            commonRule:{validator: validateData, trigger: 'blur'},
            ReasonShow:false,
            showType: false,//编辑框弹出状态
            rShow: false, //是否显示上报按钮
            pShow: false, //是否显示保存按钮
            yearList: this.GetGroupDict("ReportYear"),
            ReportStatus:'',  
            ReportId:'' , 
            Opinion:'',
            dataList:[], 
            MainVarietys:new Array(),//二维数组，用来存放品种多选的model数组
            PHTimes:new Array(),//二维数组
            TimesCycle:'' , 
            TimesCycleName:'',
            validrule:validateData,
            VarietyList:this.GetGroupDict("PotatoVariety"),
            QuarterList: this.GetGroupDict("QuarterCycleValue"), 
            //技术模式相关
            aTechmodels:["一般品种","脱毒种","抗晚疫病毒种"],
            aTechmodel:[] , 
            JZaTechmodel:[] , 
            bTechmodels:["单垄单行","单垄双行"],
            bTechmodel:[] ,
            JZbTechmodel:[] ,
            cTechmodels:["平播","平播起垄","平播后起垄","稻草免耕"],
            cTechmodel:[] ,
            JZcTechmodel:[] ,
            dTechmodels:["无覆膜","覆普通地膜","覆生物可降解地膜","膜下滴灌"],
            dTechmodel:[] ,
            JZdTechmodel:[] ,
            eTechmodels:["人工收获","机械化播种","机械化收获"],
            eTechmodel:[] ,  
            JZeTechmodel:[] ,
            //间套种植模式
            JTaTechmodels:["玉米间套马铃薯","甘蔗间套马铃薯","玉米套种秋马铃薯","烤烟套种秋马铃薯","桑园间套马铃薯"],
            JTaTechmodel:[],    
            dataModel: {//编辑模型
                Id: '',
                ReportId:'', 
                SeasonDict:'', 
                SeasonValue:'', 
                PseasonValue:'', 
                PHTime:'', 
                MainVariety:'',
                TotalArea:'', 
                TotalYield:'', 
                AvgMuYield:'', 
                MuOutput:'', 
                TotalOutput:'', 
                TechModel:'', 
                SeedCoverage:'', 
                tdSeedArea:'',
                MulchArea:'', 
                DripArea:'', 
                FertilizerArea:'', 
                NoCultivationArea:'', 
                JZArea:'', 
                JZAvgMuYield:'', 
                JZMuOutput:'', 
                JZDensity:'', 
                JZTechModel:'', 
                JTArea:'', 
                JTAvgMuYield:'', 
                JTMixMuYield:'', 
                JTMixMuOutput:'', 
                JTTechModel:'', 
                MechPlantArea:'', 
                MechCultivationArea:'', 
                MechFertilizerArea:'', 
                MechPesticideArea:'', 
                MechHarvestArea:'', 
                SeedCost:'', 
                FertilizerCost:'', 
                PesticideCost:'', 
                MulchCost:'', 
                LaborCost:'', 
                OtherCost:'', 
                TotalCost:'', 
                OAvgMuYield:'', 
                OAvgPrice:'', 
                OTotalOutput:'', 
                Income:'', 
            },
            clientHeight: window.innerHeight - 218,//表格默认高度
            //查询模型：根据需求删除不不要查询条件
            searchModel: {
                AreaCode:this.GetlocaStorage("potUserinfo").AreaCode,  
                FillInYear: new Date().getFullYear() + "",
                TimesCycle:'0',
                ReportCode:'PotSeasonProduct',
                PageNumber: 1, PageSize: 20
            },
            pageSizeOpts: [20, 40, 50],//默认分页最大设置
            datas: {},//table数据对象
            columnsList: [//表头对象
                {
                    title: '报表名称',
                    key: 'ReportCodeName',
                    ellipsis: true,
                },
                {
                    title: '归属地区',
                    key: 'AreaCodeName',
                    width: 120
                },
                {
                    title: '填报年度',
                    key: 'FillInYearName',
                    width: 120
                },
                // {
                //     title: '填报周期',
                //     key: 'TimesTypeName',
                //     width: 120
                // },
                {
                    title: '周期详情',
                    key: 'TimesCycleName',
                    width: 120
                },
                {
                    title: "报表状态",
                    key: "StatusName",
                    width: 120,
                    render: (h, params) => {
                        switch (params.row.Status * 1) {
                            case 0: //审核未通过
                                return h('span', { class: { Error: true } }, params.row.StatusName);
                            case 1: //未填报
                                return h('span', { class: { NoReport: true } }, params.row.StatusName);
                            case 2: //已填报
                                return h('span', { class: { AlreadyReport: true } }, params.row.StatusName);
                            case 3: //已上报
                                return h('span', { class: { UpReport: true } }, params.row.StatusName);
                            case 4: //审核通过
                                return h('span', { class: { Success: true } }, params.row.StatusName);
                            case 5: //锁定
                                return h('span', { class: { error: true } }, params.row.StatusName);
                            default:
                                return h('span', { class: { Default: true } }, params.row.StatusName);
                        }
                    }
                },
                {
                    title: '添加时间',
                    key: 'StrUpdateTime',
                    ellipsis: true
                },
                {
                    title: '操作',
                    key: 'action',
                    width: 320,
                    align: 'center',
                    render: (h, params) => {
                        return h('div', [
                            h('Upload', {
                                props: {
                                    //导入成功后响应窗口
                                    onSuccess: (res) => { this.handleSuccess(res) },
                                    action: this.GetPostUrl(params.row.Id),
                                    size: 'small'
                                },
                                style: {
                                    float: 'left', marginTop: '10px'
                                }
                            }, [h('Button', {
                                class: { searchButton: true },
                                props: {
                                    type: 'success', size: 'small', icon: 'ios-cloud-upload-outline'
                                },
                                attrs: {
                                    disabled: params.row.Status > 2 ? true : false
                                },
                                style: {
                                    marginRight: '5px'
                                }
                            }, '导入')]),                            
                            h('Button', {
                                //class: { ieditColor: true },
                                props: {
                                    type: 'primary', size: 'small', icon: 'ios-compose'
                                },                                
                                style: { marginRight: '5px', marginTop: '10px' },
                                on: {
                                    click: () => { 
                                        if (params.row.Status == 2) {
                                            this.rShow = true;
                                            this.pShow = true;
                                        } else if (params.row.Status <= 1) {
                                            this.pShow = true;
                                            if(params.row.Status==0){
                                                this.ReasonShow = true;
                                                this.Opinion = params.row.Opinion;
                                            }
                                        }
                                        this.TimesCycleName = params.row.TimesCycleName;
                                        this.TimesCycle = params.row.TimesCycle;
                                        this.editInfo(params.row.Id,params.row.TimesCycle);
                                    }
                                }
                            }, params.row.Status <= 2 ? "填报" : "查看"),                           
                            h('Button', {
                                //class: { ieditColor: true },
                                props: {
                                    type: 'info', size: 'small', icon: 'ios-compose'
                                },
                                attrs: {
                                    disabled: params.row.Status < 2 ? true : false
                                },
                                style: { marginRight: '5px', marginTop: '10px' },
                                on: {
                                    click: () => { this.ExcelDown(params.row.AreaCode,params.row.TimesCycle); }
                                }
                            }, '导出'),
                            h('Button', {
                                props: {
                                    type: 'warning', size: 'small', icon: 'ios-compose'
                                },
                                attrs: {
                                    disabled: params.row.Status > 2 ? true : false
                                },
                                style: { marginRight: '5px', marginTop: '10px' },
                                on: {
                                    click: () => { this.TmpDown(params.row.TimesCycle); }
                                }
                            }, '模板下载'),
                        ]);
                    }
                }]         
        }
    },
    mounted() {
        //table高度计算方法
        const that = this;
        window.onresize = () => {
            return (() => {
                that.clientHeight = window.innerHeight - 218;
            })()
        };
    },
    methods: {
        //获取当前页码
        getPageNumber(pageIndex) {
            this.searchModel.PageNumber = pageIndex;
            this.getPageData();
        },
        //获取当前分页大小
        getPageSize(pageSize) {
            this.searchModel.PageSize = pageSize;
            this.getPageData();
        },
        //获取this.datas: {},//table数据对象
        getPageData() {
            var self = this;
            self.$http.post('Report/PostPageList', this.searchModel).then(function (res) {
                if (res.data.status === 1) {
                    self.datas = res.data;
                   // self.isCreated = true;
                }
                else {
                   // self.isCreated = false;
                   // self.ReportLine = '报表未生成！';
                    self.$Modal.error({ title: '提示信息', content: res.data.message });
                }
            });
        },
        //新增
        addItem() {
            let model = {        
                Id: '',
                ReportId:'', 
                SeasonDict:'', 
                SeasonValue:'', 
                PseasonValue:'', 
                PHTime:'', 
                MainVariety:'', 
                TotalArea:'', 
                TotalYield:'', 
                AvgMuYield:'', 
                MuOutput:'', 
                TotalOutput:'', 
                TechModel:'', 
                tdSeedArea:'',
                SeedCoverage:'', 
                MulchArea:'', 
                DripArea:'', 
                FertilizerArea:'', 
                NoCultivationArea:'', 
                JZArea:'', 
                JZAvgMuYield:'', 
                JZMuOutput:'', 
                JZDensity:'', 
                JZTechModel:'', 
                JTArea:'', 
                JTAvgMuYield:'', 
                JTMixMuYield:'', 
                JTMixMuOutput:'', 
                JTTechModel:'', 
                MechPlantArea:'', 
                MechCultivationArea:'', 
                MechFertilizerArea:'', 
                MechPesticideArea:'', 
                MechHarvestArea:'', 
                SeedCost:'', 
                FertilizerCost:'', 
                PesticideCost:'', 
                MulchCost:'', 
                LaborCost:'', 
                OtherCost:'', 
                TotalCost:'', 
                OAvgMuYield:'', 
                OAvgPrice:'', 
                OTotalOutput:'', 
                Income:'', 
            };
            let sdicts = ["冬作", "小春作", "早春作"];
            let svalues = ["3-1", "3-2", "3-3"];
            if(this.TimesCycle=="3"){
                for(let i=0;i<3;i++){
                    let entity = new Object();                   
                    entity.ReportId = this.ReportId;
                    entity.SeasonDict = sdicts[i];
                    entity.SeasonValue = svalues[i];                    
                    this.dataList.push(entity);
                    this.PHTimes.push(new Array());
                }
            }else{
                let entity1 = new Object();
                entity1 = model;
                entity1.ReportId = this.ReportId;
                entity1.SeasonDict = this.dataList[0].SeasonDict;
                entity1.SeasonValue = this.dataList[0].SeasonValue;
                this.dataList.push(entity1);
                this.PHTimes.push(new Array());
            }
            
        },
        //删除对象
        delInfo(index) {
            var self = this;
            this.dataList.splice(index, 1);
        },
        //编辑获取对象传入id
        editInfo(id,TimesCycle) {//编辑
            var self = this;
            this.showType=true;
            this.ReportId = id;
            this.$http.get("PotSeasonProduct", { params: { ReportId: id,SeasonValue:TimesCycle } }).then(//获取数据编辑项的值
                function (res) {
                    if (res.data.status == 1) {
                        self.dataList = res.data.model;                         
                        if(self.dataList.length>0){
                            for(var i=0; i<self.dataList.length; i++){
                                var tItem = self.dataList[i];
                                //self.MainVarietys[i] = new Array();
                                self.PHTimes[i] = new Array();
                                // if(tItem.MainVariety){
                                // self.MainVarietys[i] = tItem.MainVariety.split("、");
                                // }
                                if(tItem.PHTime){
                                self.PHTimes[i] = tItem.PHTime.split("-");
                                }
                            }                           
                        }                       
                    }
                    else {
                        self.$Modal.error({ title: "提示信息", content: "数据加载失败!!!" });
                    }
                }
            );
        },
        //保存方法
        save(modelname) {
            var self = this;
            this.$refs[modelname].validate((valid) => {
                if (valid) {
                    
                    // for(var i=0; i<this.PHTimes.length; i++){
                    //     let tItem1 = new Array();
                    //     //tItem = this.MainVarietys[i];
                    //     tItem1 = this.PHTimes[i];
                    //     // if(tItem){
                    //     //     this.dataList[i].MainVariety = tItem.join("、");
                    //     // }
                    //     if(tItem1){
                    //         this.dataList[i].PHTime = tItem1.join("-");
                    //     }
                    // }
                    this.$http.post('PotSeasonProduct', this.dataList).then(
                        function (res) {
                            if (res.data.status == 1) {
                                self.getPageData();//读取分页数据
                                self.rShow = true;
                                self.$Notice.success({ title: '保存成功！', desc: false });
                            }
                            else {
                                self.$Modal.warning({ title: "提示信息", content: res.data.message });
                            }
                    });
                     
                }
                else{
                    self.$Modal.warning({ title: "提示信息", content: '无法保存，请检查是否有未填项！' });
                }
            });
        },
        //数据上报
        DataUp() {
            var self = this;
            let model = new Object();
            model.Id = this.ReportId;
            model.Status = 3;
            model.Opinion = '';
            self.$Modal.confirm({
                title: '提示信息',
                content: '<p>数据上报后，不能再更改，是否继续上报？</p>',
                onOk: () => {
                    this.$http.post("Report/PostUpStatus", model).then(
                        function (res) {
                            if (res.data.status == 1) {
                                self.showType = false;
                                self.$Notice.success({ title: '数据上报成功！', desc: false });
                                self.getPageData();
                            }
                            else {
                                self.$Modal.error({ title: "提示信息", content: "数据上报失败!" });
                            }
                        }
                    );
                }
            });
        },
        saveTechModel(index){
            var str = '';
           if(this.aTechmodel.length > 0){
               str += this.aTechmodel.join("、");
               str += '-';
           }
           if(this.bTechmodel.length > 0){
               str += this.bTechmodel.join("、");
               str += '-';
           }
           if(this.cTechmodel.length > 0){
               str += this.cTechmodel.join("、");
               str += '-';
           }
           if(this.dTechmodel.length > 0){
               str += this.dTechmodel.join("、");
               str += '-';
           }
           if(this.eTechmodel.length > 0){
               str += this.eTechmodel.join("、");
           }
           if(str){
               this.dataList[index].TechModel = str;
           }
           this.aTechmodel = [];
           this.bTechmodel = [];
           this.cTechmodel = [];
           this.dTechmodel = [];
           this.eTechmodel = [];
        },
        saveJZTechModel(index){
            var str = '';
           if(this.JZaTechmodel.length > 0){
               str += this.JZaTechmodel.join("、");
               str += '-';
           }
           if(this.JZbTechmodel.length > 0){
               str += this.JZbTechmodel.join("、");
               str += '-';
           }
           if(this.JZcTechmodel.length > 0){
               str += this.JZcTechmodel.join("、");
               str += '-';
           }
           if(this.JZdTechmodel.length > 0){
               str += this.JZdTechmodel.join("、");
               str += '-';
           }
           if(this.JZeTechmodel.length > 0){
               str += this.JZeTechmodel.join("、");
           }        
           if(str){
                this.dataList[index].JZTechModel = str;
           }
           this.JZaTechmodel = [];
           this.JZbTechmodel = [];
           this.JZcTechmodel = [];
           this.JZdTechmodel = [];
           this.JZeTechmodel = [];
        },
        saveJTTechModel(index){
            var str = '';
           if(this.JTaTechmodel.length > 0){
               str += this.JTaTechmodel.join("、");
           }
           if(str)
           this.dataList[index].JTTechModel = str;
           this.JTaTechmodel = [];
        },
        //模板下载
        TmpDown:function(TimesCycle){
            let ReportCodestr = this.searchModel.ReportCode + TimesCycle;
            window.open(this.$http.defaults.baseURL + "Report/GetTemplateData?ReportCode=" + ReportCodestr);
        },
        //导入
        GetPostUrl(ReportId) {
            var url = this.$http.defaults.baseURL + "PotSeasonProduct/PostImportData?ReportId=" + ReportId;
            return url;
        },
        //导入成功反馈事件
        handleSuccess(res) {
            var self = this;
            self.getPageData();
            if(res.status == -1){
                self.$Modal.warning({
                    title: "提示信息",
                    content: res.message
                });
            }else{
                self.$Notice.success({
                    title: '数据导入成功！',
                    desc: false
                });
            }            
        },
        //导出
        ExcelDown: function (AreaCode,TimesCycle) {           
            window.open(this.$http.defaults.baseURL + "PotSeasonProduct/GetExcelData?FillInYear=" + this.searchModel.FillInYear + "&&AreaCode=" + AreaCode+"&&TimesCycle=" + TimesCycle);
        },
        initTimesCycle(){
            var self = this;
            var today = new Date();
            let currentMonth = today.getMonth() + 1;
            if(currentMonth>=5 && currentMonth<=8){
                this.searchModel.TimesCycle = '3';
            }
            else if(currentMonth>=9 && currentMonth<=11){
                this.searchModel.TimesCycle = '2';
            }
            else{
                this.searchModel.TimesCycle = '1';
            }
        },
        initReport(){
            var today = new Date();
            let currentYear = today.getFullYear();
            let currentMonth = today.getMonth() + 1;
            if(this.searchModel.FillInYear*1 == currentYear){
                if(currentMonth>=5 && currentMonth<=8 && this.searchModel.TimesCycle == '3'){
                    this.getPageData();
                }
                else if(currentMonth>=9 && currentMonth<=11 && this.searchModel.TimesCycle == '2'){
                    this.getPageData();
                }
                else if(currentMonth==12&& this.searchModel.TimesCycle == '1'){
                    this.getPageData();
                }
                else{
                    this.isCreated = false;
                    this.ReportLine = '不在填报时间内！';
                }
            }
            else {
                this.isCreated = false;
                this.ReportLine = '不在填报时间内！';
            }
        }
    },
    //创建Vue页面方法
    created: function () {
        //创业Vue前调用获取this.datas: {},//table数据对象
       // this.initTimesCycle();
        //this.initReport();
        this.getPageData();
    },
    watch: {
        //需要监听的在此处新增监听对象
    }
}
</script>
<style scoped>
.hrdiv{
    margin-top: 15px;
    margin-bottom:15px;
}
.hr1{
    height:3px;
    border:none;
    border-top:3px double #1E90FF;
}
.hr2{
    height:3px;
    border:none;
    border-top:3px double #ff9900;
}
</style>
